var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Page({
    data: {
        form: {
            name: "",
            card: "",
            bank: "",
            card_type: "",
            identity: "",
            mobile: "",
            cvv2: "",
            valid_day: ""
        },
        step: 1,
        bankShow: !1,
        cardShow: !1,
        radio: "",
        radioCard: "",
        bankArr: [ "中信银行", "上海银行", "光大银行", "民生银行", "北京银行", "平安银行", "交通银行", "招行银行", "招行银行", "广发银行", "华夏银行", "建设银行", "农业银行", "浦发银行", "邮储银行" ],
        bankCard: [ {
            name: "储蓄卡",
            id: 1
        }, {
            name: "信用卡",
            id: 2
        } ],
        timeShow: !1,
        maxDate: new Date().getTime(),
        currentDate: new Date().getTime(),
        imgcode: "",
        imgcodeShow: !1,
        sms: "",
        smsMobile: "",
        btnText: "获取验证码",
        timer: null,
        btnTag: !1,
        order_pay_id: ""
    },
    onLoad: function(t) {
        wx.setNavigationBarTitle({
            title: "添加银行卡"
        }), t.order_pay_id && this.setData({
            order_pay_id: t.order_pay_id
        }), t.sn && this.setData({
            sn: t.sn
        }), t.money && this.setData({
            money: t.money
        });
    },
    valInp: function(a) {
        var e = a.detail.type, o = a.detail.value;
        this.setData(t({}, "form." + e, o));
    },
    childParams: function(t) {
        var a = t.detail;
        "valid_day" == a ? this.setData({
            timeShow: !0
        }) : "card_type" == a ? this.setData({
            cardShow: !0
        }) : "bank" == a && this.setData({
            bankShow: !0
        });
    },
    cardShowClose: function() {
        this.setData({
            cardShow: !1
        });
    },
    bankShowClose: function() {
        this.setData({
            bankShow: !1
        });
    },
    bankRadio: function(t) {
        var a = t.detail;
        this.setData({
            radio: a
        });
    },
    bankCardRadio: function(t) {
        this.setData({
            radioCard: t.detail
        });
    },
    onClickRight: function() {
        this.setData({
            "form.bank": this.data.radio,
            bankShow: !1
        });
    },
    onClickRight_timeShow: function(t) {
        var a = this.timestampToTime(t.detail);
        this.setData({
            "form.valid_day": a,
            timeShow: !1
        });
    },
    onClickRight_cardShow: function() {
        this.setData({
            "form.card_type": "储蓄卡" == this.data.radioCard ? 1 : 2,
            cardShow: !1
        });
    },
    timeShowClose: function() {
        this.setData({
            timeShow: !1
        });
    },
    timestampToTime: function(t) {
        if (!Number(t) || "" == t) return "";
        var a = new Date(t), e = a.getFullYear();
        return (a.getMonth() + 1 < 10 ? "0" + (a.getMonth() + 1) : a.getMonth() + 1) + e;
    },
    next: function() {
        console.log(this.data.form, "dddddddd"), 1 == this.data.step && this.verify() && (this.setData({
            step: 2
        }), this.getimgStatus());
    },
    smsInp: function(t) {
        this.setData({
            sms: t.detail
        }), console.log(this.data.sms);
    },
    smsMobileInp: function(t) {
        this.setData({
            smsMobile: t.detail
        }), console.log(this.data.smsMobile);
    },
    verify: function() {
        if (a._isTextEmpty(this.data.form.name)) return wx.showModal({
            content: "请输入持卡人姓名",
            showCancel: !1
        }), !1;
        if (a._isTextEmpty(this.data.form.card)) return wx.showModal({
            content: "请输入卡号",
            showCancel: !1
        }), !1;
        if (a._isTextEmpty(this.data.form.bank)) return wx.showModal({
            content: "请选择所属银行",
            showCancel: !1
        }), !1;
        if (a._isTextEmpty(this.data.form.card_type)) return wx.showModal({
            content: "请选择银行卡类型",
            showCancel: !1
        }), !1;
        if (a._isTextEmpty(this.data.form.identity)) return wx.showModal({
            content: "请输入证件号",
            showCancel: !1
        }), !1;
        if (a._isTextEmpty(this.data.form.mobile)) return wx.showModal({
            content: "请输入银行卡预留手机号",
            showCancel: !1
        }), !1;
        if (2 == this.data.form.card_type) {
            if (a._isTextEmpty(this.data.form.cvv2)) return wx.showModal({
                content: "请输入卡背面末三位",
                showCancel: !1
            }), !1;
            if (a._isTextEmpty(this.data.form.valid_day)) return wx.showModal({
                content: "请选择月份/年份",
                showCancel: !1
            }), !1;
        }
        return !0;
    },
    getimgStatus: function() {
        var t = this, e = a.getNetAddresss("plugin.silver-point-pay.frontend.union-card.captcha-status");
        a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.setData({
                    imgcodeShow: !0
                }), t.getimgdata()) : (t.setData({
                    imgcodeShow: !1
                }), wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getimgdata: function() {
        var t = this, e = a.getNetAddresss("home-page.getCaptcha");
        a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                e.data.captcha && (t.setData({
                    imgcode: e.data.captcha.img
                }), console.log(t.data.imgcode, "dddddddddd"));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    checkCodeMethod: function() {
        this.imgcodeShow ? this.checkCaptcha() : this.firstNext();
    },
    checkCaptcha: function() {
        var t = this, e = a.getNetAddresss("plugin.silver-point-pay.frontend.union-card.captcha");
        a._getNetWork({
            url: e,
            data: {
                code: this.data.sms
            },
            success: function(a) {
                var e = a.data;
                e.result ? t.firstNext() : (t.getimgdata(), wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    firstNext: function() {
        var t = this, e = {
            card: this.data.form.card,
            bank: this.data.form.bank,
            name: this.data.form.name,
            identity: this.data.form.identity,
            mobile: this.data.form.mobile,
            card_type: this.data.form.card_type
        };
        2 == this.data.form.card_type && (e.valid_day = this.data.form.valid_day, e.cvv2 = this.data.form.cvv2);
        var o = a.getNetAddresss("plugin.silver-point-pay.frontend.union-card.bind-card");
        a._getNetWork({
            url: o,
            data: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.setData({
                    token: e.data.token,
                    pay_union_card_id: e.data.pay_union_card_id
                }), t.sendCodeAnimation()) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    sendCodeAnimation: function() {
        var t = this;
        this.data.timer || (this.data.count = 60, wx.showToast({
            title: "验证码已发送",
            icon: "success",
            duration: 1e3
        }), this.data.timer = setInterval(function() {
            t.data.count > 0 && t.data.count <= 60 ? (t.data.count--, t.setData({
                btnTag: !0,
                btnText: t.data.count + "s"
            })) : (t.setData({
                btnTag: !1,
                btnText: "获取验证码"
            }), clearInterval(t.data.timer), t.data.timer = null);
        }, 1e3));
    },
    confirmBtn: function() {
        a._isTextEmpty(this.smsMobile) ? wx.showModal({
            content: "请输入短信验证码",
            showCancel: !1
        }) : this.checkPhoneCode();
    },
    checkPhoneCode: function() {
        var t = this, e = {
            code: this.data.smsMobile,
            token: this.data.token,
            pay_union_card_id: this.data.pay_union_card_id
        }, o = a.getNetAddresss("plugin.silver-point-pay.frontend.union-card.sms");
        a._getNetWork({
            url: o,
            data: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.data.order_pay_id || wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3,
                    success: function(t) {
                        setTimeout(function() {
                            wx.navigateTo({
                                url: "/packageF/silverPointPay/SilverBankList/SilverBankList"
                            });
                        }, 1e3);
                    }
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});